package concurrency.chapter7;

public class BankVersion2 {
    public static void main(String[] args) {
        //Runnable方式的好处是，业务逻辑的实例只有一个
        final TicketWindowRunnable ticketWindowRunnable = new TicketWindowRunnable();
        Thread t1 = new Thread(ticketWindowRunnable, "一号窗口");
        Thread t2 = new Thread(ticketWindowRunnable, "二号窗口");
        Thread t3 = new Thread(ticketWindowRunnable, "三号窗口");
        t1.start();
        t2.start();
        t3.start();
        //线程的数据同步用synchronized，可以防止下边的情况发生
        //三号窗口的号码是：367
        //二号窗口的号码是：368
        //一号窗口的号码是：367
        //三号窗口的号码是：369
        //二号窗口的号码是：369
        //一号窗口的号码是：369
        //二号窗口的号码是：370
        //......
        //一号窗口的号码是：500
        //二号窗口的号码是：502
        //三号窗口的号码是：501
    }
}
